﻿using LPLS.DBEntities.ConfigModels;
using LPLS.DBInterface.ConfigModels;
using LPLS.PluginCommon.ModulePlugin;
using Microsoft.Win32;
using Prism.Commands;
using Prism.Ioc;
using Prism.Mvvm;
using PropertyConfigModule.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace PropertyConfigModule.ViewModels
{

    [ViewModelMetadata(projectID: "12322222", viewModelName: "配置", version: "1.0.1", lifecycle: Lifecycle.Singleton, index: 0, isCommon: true)]
    public  class ConfigViewModel : BindableBase
    {

        private readonly IContainerProvider _containerProvider;
      
        public DelegateCommand Click { get; private set; }
        private ObservableCollection<TabItem> _tabItems;
        public ObservableCollection<TabItem> TabItems
        {
            get { return _tabItems; }
            set { SetProperty(ref _tabItems, value); }
        }

        public ConfigViewModel(IContainerProvider containerProvider)
        {


            _containerProvider= containerProvider;

                  Click = new DelegateCommand(OpenFileDialog);
            InitializeTabs();
            
        }



        private void OpenFileDialog() 
        { 
        
        
        
        }
        private void InitializeTabs()
        {
            TabItems = new ObservableCollection<TabItem>
        {
            CreateTabItem("属性配置", typeof(PropertyConfigView)),
          //    CreateTabItem("属性配置", typeof(PropertyConfigView)),
        };
        }

        private TabItem CreateTabItem(string header, Type viewType)
        {
            // 创建视图
            var view = _containerProvider.Resolve(viewType) as FrameworkElement;

            // 创建代理容器
            var contentHost = new ContentControl();

            // 保持原始 DataContext
            contentHost.Content = view;
            contentHost.DataContext = view.DataContext;

            return new TabItem
            {
                Header = header,
                Content = contentHost // 使用代理容器
            };
        }




    }
}
